<template> 
	<div class="JNPF-common-layout">
		<div class="JNPF-common-layout-center">
			<el-row class="JNPF-common-search-box" :gutter="16">
				<el-form @submit.native.prevent>
					<el-col :span="6">
						<el-form-item label="隐患名称">
							<el-input v-model="query.yhmc" placeholder="隐患名称" clearable  />
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="隐患状态">
							<el-select v-model="query.yhzt" placeholder="隐患状态" clearable >
								<el-option v-for="(item, index) in yhztOptions" :key="index" :label="item.fullName" :value="item.id"  />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="6">
					<el-form-item>
						<el-button type="primary" icon="el-icon-search" @click="search()">查询</el-button>
						<el-button icon="el-icon-refresh-right" @click="reset()">重置</el-button>
					</el-form-item>
					</el-col>
				</el-form>
			</el-row>
			<div class="JNPF-common-layout-main JNPF-flex-main">
				<div class="JNPF-common-head">
					<div>
						<!-- <el-button type="primary" icon="el-icon-plus" @click="addOrUpdateHandle()">
							新增
						</el-button> -->
						<el-button type="text" icon="el-icon-download" @click="exportData()">
							导出
						</el-button>
					</div>
					<div class="JNPF-common-head-right">
						<el-tooltip effect="dark" content="刷新" placement="top">
							<el-link icon="icon-ym icon-ym-Refresh JNPF-common-head-icon" :underline="false"  @click="reset()" />
						</el-tooltip>
						<screenfull :isContainer="true" />
						<el-tooltip effect="dark" content="列设置" placement="top">
							<el-link icon="icon-ym icon-ym-options JNPF-common-head-icon" :underline="false" />
						</el-tooltip>
					</div>
				</div>
				<JNPF-table v-loading="listLoading" :data="list">
					<el-table-column prop="fxd" label="风险点" align="left" />
					<el-table-column prop="pcx" label="排查项" align="left" />
					<el-table-column prop="yhmc" label="隐患名称" align="left" />
					<el-table-column prop="yhms" label="隐患描述" align="left" />
					<!-- <el-table-column label="隐患责任部门"  prop="yhzrbm" algin="left">
						<template slot-scope="scope">{{ scope.row.yhzrbm | dynamicText(yhzrbmOptions) }}</template>
					</el-table-column>
					<el-table-column prop="yhdd" label="隐患地点" align="left" />
					<el-table-column label="隐患上报人"  prop="yhsbr" algin="left">
						<template slot-scope="scope">{{ scope.row.yhsbr | dynamicText(yhsbrOptions) }}</template>
					</el-table-column> 
					<el-table-column label="隐患核查人"  prop="yhhcr" algin="left">
						<template slot-scope="scope">{{ scope.row.yhhcr | dynamicText(yhhcrOptions) }}</template>
					</el-table-column>
					<el-table-column prop="sbsj" label="隐患上报时间" align="left" width="150"/>
					<el-table-column label="判定人"  prop="pdr" algin="left">
						<template slot-scope="scope">{{ scope.row.pdr | dynamicText(pdrOptions) }}</template>
					</el-table-column>
					<el-table-column label="是否为隐患"  prop="sfwyh" algin="left">
						<template slot-scope="scope">{{ scope.row.sfwyh | dynamicText(sfwyhOptions) }}</template>
					</el-table-column> -->
					<el-table-column prop="hcyj" label="隐患核查意见" align="left" />
					<el-table-column label="隐患核查结果"  prop="hcjg" algin="left">
						<template slot-scope="scope">{{ scope.row.hcjg | dynamicText(hcjgOptions) }}</template>
					</el-table-column>
					<el-table-column prop="yhzlcs" label="隐患治理措施" align="left" />
					<el-table-column label="隐患核查部门"  prop="yhhcbm" algin="left">
						<template slot-scope="scope">{{ scope.row.yhhcbm | dynamicText(yhhcbmOptions) }}</template>
					</el-table-column>
					<el-table-column label="隐患整改责任人"  prop="yhzgzrr" algin="left">
						<template slot-scope="scope">{{ scope.row.yhzgzrr | dynamicText(yhzgzrrOptions) }}</template>
					</el-table-column>
					<el-table-column prop="yhhcsj" label="隐患核查日期" align="left" />
					<el-table-column prop="wcqx" label="完成期限" align="left" width="150"/>
					<!-- <el-table-column prop="zgqk" label="隐患整改情况" align="left" />
					<el-table-column prop="zgzj" label="隐患整改资金" align="left" />
					<el-table-column label="隐患整改部门"  prop="zgbm" algin="left">
						<template slot-scope="scope">{{ scope.row.zgbm | dynamicText(zgbmOptions) }}</template>
					</el-table-column>
					<el-table-column prop="zgcs" label="隐患整改措施" align="left" />
					<el-table-column label="隐患验收人"  prop="yhysr" algin="left">
						<template slot-scope="scope">{{ scope.row.yhysr | dynamicText(yhysrOptions) }}</template>
					</el-table-column>
					<el-table-column prop="yhzgsj" label="隐患整改时间" align="left" />
					<el-table-column prop="ysyj" label="验收意见" align="left" />
					<el-table-column label="验收结果"  prop="ysjg" algin="left">
						<template slot-scope="scope">{{ scope.row.ysjg | dynamicText(ysjgOptions) }}</template>
					</el-table-column>
					<el-table-column prop="yssj" label="验收时间" align="left" />  -->
					<el-table-column label="隐患状态"  prop="yhzt" algin="left">
						<template slot-scope="scope">{{ scope.row.yhzt | dynamicText(yhztOptions) }}</template>
					</el-table-column>
					<el-table-column label="操作" fixed="right" width="100">
						<template slot-scope="scope">
							<el-button type="text" v-if="scope.row.yhhcr==CurrentLogin && scope.row.yhzt == '2'" @click="addOrUpdateHandle(scope.row.id)" >
								核查
							</el-button>
							<!-- <el-button type="text" @click="handleDel(scope.row.id)" class="JNPF-table-delBtn">
								删除
							</el-button> -->
							<el-button type="text" @click="addOrUpdateHandle(scope.row.id,true)" >
								详情
							</el-button>
						</template>
					</el-table-column>
				</JNPF-table>
				<pagination :total="total" :page.sync="listQuery.currentPage" :limit.sync="listQuery.pageSize" @pagination="initData" />
			</div>
		</div>
		<JNPF-Form v-if="formVisible" ref="JNPFForm" @refresh="refresh" />
		<ExportBox v-if="exportBoxVisible" ref="ExportBox" @download="download" />
	</div>

</template> 
<script>
    import request from '@/utils/request'
    import {getDictionaryDataSelector} from '@/api/systemData/dictionary'
    import JNPFForm from './Form'
    import ExportBox from './ExportBox'
    import {previewDataInterface} from '@/api/systemData/dataInterface'
	import { mapGetters } from 'vuex'
    export default {
        components: {JNPFForm, ExportBox},
        data() {
            return {
				 CurrentLogin:'',
                    showAll: false,
                query: {
					yhmc:undefined,
					yhzt:'2',
					bs: '2'

                },
                defaultProps: {
                    children: 'children',
                    label: 'fullName'
                },
                list: [],
                listLoading: true,
                total: 0,
                listQuery: {
					currentPage: 1,
					pageSize: 20,

                    sort: "desc",
                    sidx: "",
                },
                formVisible: false,
                exportBoxVisible: false,
                columnList: [
					{prop: 'fxd', label: '风险点'},
					{prop: 'pcx', label: '排查项'},
					{prop: 'yhmc', label: '隐患名称'},
					{prop: 'yhms', label: '隐患描述'},
					{prop: 'yhzrbm', label: '隐患责任部门'},
					{prop: 'yhdd', label: '隐患地点'},
					{prop: 'yhsbr', label: '隐患上报人'},
					{prop: 'yhhcr', label: '隐患核查人'},
					{prop: 'sbsj', label: '隐患上报时间'},
					{prop: 'pdr', label: '判定人'},
					{prop: 'sfwyh', label: '是否为隐患'},
					{prop: 'hcyj', label: '隐患核查意见'},
					{prop: 'hcjg', label: '隐患核查结果'},
					{prop: 'yhzlcs', label: '隐患治理措施'},
					{prop: 'yhhcbm', label: '隐患核查部门'},
					{prop: 'yhzgzrr', label: '隐患整改责任人'},
					{prop: 'yhhcsj', label: '隐患核查日期'},
					{prop: 'wcqx', label: '完成期限'},
					{prop: 'zgqk', label: '隐患整改情况'},
					{prop: 'zgzj', label: '隐患整改资金'},
					{prop: 'zgbm', label: '隐患整改部门'},
					{prop: 'zgcs', label: '隐患整改措施'},
					{prop: 'yhysr', label: '隐患验收人'},
					{prop: 'yhzgsj', label: '隐患整改时间'},
					{prop: 'ysyj', label: '验收意见'},
					{prop: 'ysjg', label: '验收结果'},
					{prop: 'yssj', label: '验收时间'},
					{prop: 'yhzt', label: '隐患状态'},

                ],
				// pcxOptions:[{"fullName":"aa","id":"1"},{"fullName":"bb","id":"2"}],
				yhzrbmOptions:[],
				yhsbrOptions:[],
				yhhcrOptions:[],
				pdrOptions:[],
				sfwyhOptions:[{"fullName":"是","id":"0"},{"fullName":"否","id":"1"}],
				hcjgOptions:[{"fullName":"未通过","id":"0"},{"fullName":"已通过","id":"1"}],
				yhhcbmOptions:[],
				yhzgzrrOptions:[],
				zgbmOptions:[],
				yhysrOptions:[],
				ysjgOptions:[{"fullName":"不通过","id":"0"},{"fullName":"通过","id":"1"}],
				yhztOptions:[{"fullName":"全部","id":""},{"fullName":"待判定","id":"0"},{"fullName":"未构成隐患","id":"1"},{"fullName":"待核查","id":"2"},{"fullName":"待整改","id":"3"},{"fullName":"待验收","id":"4"},{"fullName":"验收通过","id":"5"},{"fullName":"验收未通过","id":"6"}],

            }
        },
        computed: {
			...mapGetters(['userInfo'])
		},
        created() {
			this.initData();
			this.getyhzrbmOptions();
			this.getyhsbrOptions();
			this.getyhhcrOptions();
			this.getpdrOptions();
			this.getyhhcbmOptions();
			this.getyhzgzrrOptions();
			this.getzgbmOptions();
			this.getyhysrOptions();
			this.CurrentLogin = this.userInfo.userName


        },
        methods: {
		getyhzrbmOptions()
		{
			previewDataInterface('772d2cbcadd24df79243e3d92ef5f690').then(res => {
				this.yhzrbmOptions = res.data
			})
		},
		getyhsbrOptions()
		{
			previewDataInterface('8bca424f16d6448ab09e57a028853aa9').then(res => {
				this.yhsbrOptions = res.data
			})
		},
		getyhhcrOptions()
		{
			previewDataInterface('8bca424f16d6448ab09e57a028853aa9').then(res => {
				this.yhhcrOptions = res.data
			})
		},
		getpdrOptions()
		{
			previewDataInterface('8bca424f16d6448ab09e57a028853aa9').then(res => {
				this.pdrOptions = res.data
			})
		},
		getyhhcbmOptions()
		{
			previewDataInterface('772d2cbcadd24df79243e3d92ef5f690').then(res => {
				this.yhhcbmOptions = res.data
			})
		},
		getyhzgzrrOptions()
		{
			previewDataInterface('8bca424f16d6448ab09e57a028853aa9').then(res => {
				this.yhzgzrrOptions = res.data
			})
		},
		getzgbmOptions()
		{
			previewDataInterface('772d2cbcadd24df79243e3d92ef5f690').then(res => {
				this.zgbmOptions = res.data
			})
		},
		getyhysrOptions()
		{
			previewDataInterface('8bca424f16d6448ab09e57a028853aa9').then(res => {
				this.yhysrOptions = res.data
			})
		},


            initData() {
                this.listLoading = true;
                let query = {
                    ...this.listQuery,
                    ...this.query
                };
                request({
                    url: `/api/System/qyaqscYhpcxx`,
                    method: 'get',
                    data: query
                }).then(res => {
                    this.list = res.data.list
                    this.total = res.data.pagination.total
                    this.listLoading = false
                    this.$nextTick(() => {
                        this.tableHeight = "100%"
                    });
                })
            },
            handleDel(id) {
                this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
                    type: 'warning'
                }).then(() => {
                    request({
                        url: `/api/System/qyaqscYhpcxx/${id}`,
                        method: 'DELETE'
                    }).then(res => {
                        this.$message({
                            type: 'success',
                            message: res.msg,
                            onClose: () => {
                                this.initData()
                            }
                        });
                    })
                }).catch(() => {
                });
            },
            addOrUpdateHandle(id,isDetail) {
                this.formVisible = true
                this.$nextTick(() => {
                    this.$refs.JNPFForm.init(id,isDetail)
                })
            },
            exportData() {
                this.exportBoxVisible = true
                this.$nextTick(() => {
                    this.$refs.ExportBox.init(this.columnList)
                })
            },
            download(data) {
                let query = {...data, ...this.listQuery, ...this.query}
                request({
                    url: `/api/System/qyaqscYhpcxx/Actions/Export`,
                    method: 'POST',
                    data: query
                }).then(res => {
                    if (!res.data.url) return
                    window.location.href = this.define.comUrl + res.data.url
                    this.$refs.ExportBox.visible = false
                    this.exportBoxVisible = false
                })
            },
            search() {
                this.listQuery = {
					currentPage: 1,
					pageSize: 20,

                    sort: "desc",
                    sidx: "",
                }
                this.initData()
            },
            refresh(isrRefresh) {
                this.formVisible = false
                if (isrRefresh) this.reset()
            },
            reset() {
                for (let key in this.query) {
                    this.query[key] = undefined
                }
                this.listQuery = {
					currentPage: 1,
					pageSize: 20,

                    sort: "desc",
                    sidx: "",
                }
                this.initData()
            }
        }
    }
</script>